package test.san.baseproject.net

import com.google.gson.Gson
import java.lang.reflect.ParameterizedType

open class MRequest<PESPONSE>(val url: String, val handler: ResponseHandler<PESPONSE>) {

    // 解析网络请求数据
    fun parseResult(result: String?): PESPONSE? {

        val gson = Gson()
        // 获取泛型类型
        val type = (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]
        val list = gson.fromJson<PESPONSE>(result, type)
        return list
    }

    fun excute() {
        NetManager.manager.sendRequest(this)
    }
}